package cn.keniykey.mc.landterritory.landview;

import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.regex.Pattern;

import javax.annotation.Nullable;

import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import cn.keniykey.mc.generallibrary.input.api.EInputResult;
import cn.keniykey.mc.generallibrary.input.api.IInputRequestManager;
import cn.keniykey.mc.generallibrary.input.api.IInputResultHandler;
import cn.keniykey.mc.landterritory.LandTerritoryMain;
import cn.keniykey.mc.landterritory.config.ConfigurationManager;
import cn.keniykey.mc.landterritory.config.LanguageManager;
import cn.keniykey.mc.landterritory.config.ViewsConfiguration;
import cn.keniykey.mc.landterritory.config.WorldsConfiguration;
import cn.keniykey.mc.landterritory.config.ViewsConfiguration.ViewConfig;
import cn.keniykey.mc.landterritory.database.DataBaseManager;
import cn.keniykey.mc.landterritory.event.LandRangeUpdateEvent;
import cn.keniykey.mc.landterritory.event.LandUpdateDataEvent;
import cn.keniykey.mc.landterritory.land.LandManager;
import cn.keniykey.mc.landterritory.land.LandRangeToolListener;
import cn.keniykey.mc.landterritory.land.LandTransferUtil;
import cn.keniykey.mc.landterritory.land.RangeShowManager;
import cn.keniykey.mc.landterritory.land.api.ELandType;
import cn.keniykey.mc.landterritory.land.api.Land;
import cn.keniykey.mc.landterritory.land.api.LandPosition;
import cn.keniykey.mc.landterritory.land.api.LandRange;
import cn.keniykey.mc.landterritory.land.api.LandUtil;
import cn.keniykey.mc.landterritory.land.api.LandUtil.ELandPermissionLevel;
import cn.keniykey.mc.landterritory.toolkit.ArithmeticUtil;
import cn.keniykey.mc.landterritory.toolkit.Util;
import cn.keniykey.mc.landterritory.vault.Econ;
import cn.keniykey.mc.viewlibrary.container.api.EContainerType;
import cn.keniykey.mc.viewlibrary.view.api.AbFrameView;
import cn.keniykey.mc.viewlibrary.view.api.FrameViewBundle;
import cn.keniykey.mc.viewlibrary.view.api.FrameViewIntent;
import cn.keniykey.mc.viewlibrary.view.api.IViewClickHandler;
import cn.keniykey.mc.viewlibrary.view.api.ViewClickReport;
import cn.keniykey.mc.viewlibrary.view.api.template.AbChooseView.EChooseResult;
import cn.keniykey.mc.viewlibrary.view.api.template.AbChooseView.EChooseResultIntentKey;
import cn.keniykey.mc.viewlibrary.view.api.template.ChooseViewIntentBuilder;

public final class LandInfoView extends AbLandFrameView{

	protected LandInfoView(Player player1) {
		super(player1);
	}

	private static final String VIEW_NAME = "landinfo";
	private static final int CODE_CHOOSE_SYSTEM = 10700;
	private static final int CODE_CHOOSE_DELETE = 10701;
	private static final int CODE_CHOOSE_SETPOS = 10702;
	private static final int CODE_CHOOSE_NOTLEAVETIP = 10703;
	private static final int CODE_CHOOSE_NOTENTERTIP = 10704;
	private static final int CODE_CHOOSE_OVERLAP =10705;
	private static final int CODE_CHOOSE_EXPAND = 10706;
	private static final int CODE_CHOOSE_REDUCE = 10707;
	private static final int CODE_CHOOSE_CHANGE = 10708;
	
	private Land land;
	
	@Override
	protected void onCreate() {
		super.onCreate();
		this.land = this.getIntent().getExtras().getValue("land", null);
		
		final ViewConfig config_view = ViewsConfiguration.getViewConfig(VIEW_NAME);
		this.setViewType(EContainerType.matchContainer(config_view.getViewSize()));
		this.setTitle(Util.conver(config_view.getViewTitle()));
		
		this.setIconClick(config_view.getViewItemSlot("back"), config_view.getViewItem("back"), AbLandFrameView.CLICK_BACK);
		this.setIconClick(config_view.getViewItemSlot("flags"), config_view.getViewItem("flags"), new IViewClickHandler() {
			@Override
			public void onClick(Player player, AbFrameView view, ViewClickReport report) {
				if(!LandInfoView.this.isMatchClickSpeed()) return;
				final FrameViewIntent intent = new FrameViewIntent(LandFlagListView.class);
				final FrameViewBundle fvb = new FrameViewBundle();
				fvb.putValue("land", LandInfoView.this.land);
				intent.putExtras(fvb);
				LandInfoView.this.showView(intent);
			}
		});
		this.setIconClick(config_view.getViewItemSlot("transfer"), config_view.getViewItem("transfer"), new IViewClickHandler() {
			@Override
			public void onClick(Player player, AbFrameView view, ViewClickReport report) {
				if(!LandInfoView.this.isMatchClickSpeed()) return;
				LandTransferUtil.transferLand(player, LandInfoView.this.land, true, true);
				view.finishAll();
			}
		});
		this.setIconClick(config_view.getViewItemSlot("show"), config_view.getViewItem("show"), new IViewClickHandler() {
			@Override
			public void onClick(Player player, AbFrameView view, ViewClickReport report) {
				if(!LandInfoView.this.isMatchClickSpeed()) return;
				RangeShowManager.showRange(player, LandInfoView.this.land.getRange().clone(), true);
				view.finishAll();
			}
		});
		this.setIconClick(config_view.getViewItemSlot("owner"), config_view.getViewItem("owner"), new IViewClickHandler() {
			@Override
			public void onClick(Player player, AbFrameView view, ViewClickReport report) {
				if(!LandInfoView.this.isMatchClickSpeed()) return;
				IInputRequestManager.getIInputRequestManager().requestInput(player, "s", ConfigurationManager.View_Choose_Countdown, true, new IInputResultHandler() {
					@Override
					public boolean onInputResult(EInputResult result, OfflinePlayer offplayer, @Nullable String str) {
						boolean cancel = true;
						if(EInputResult.INPUT.equals(result)) {
							cancel = changeLandOwner(player, LandInfoView.this.land, str);
						}
						LandViewUtil.inputResultResponse(result, offplayer, cancel, 1107150);
						return cancel;
					}
				});
				player.sendMessage(LanguageManager.getChatLang(1107155, "s", LandViewUtil.getLandLabelStr(LandInfoView.this.land)));
				view.finishAll();
			}
		});
		this.setIconClick(config_view.getViewItemSlot("name"), config_view.getViewItem("name"), new IViewClickHandler() {
			@Override
			public void onClick(Player player, AbFrameView view, ViewClickReport report) {
				if(!LandInfoView.this.isMatchClickSpeed()) return;
				IInputRequestManager.getIInputRequestManager().requestInput(player, "s", ConfigurationManager.View_Choose_Countdown, true, new IInputResultHandler() {
					@Override
					public boolean onInputResult(EInputResult result, OfflinePlayer offplayer, @Nullable String str) {
						boolean cancel = true;
						if(EInputResult.INPUT.equals(result)) {
							cancel = changeLandName(player, LandInfoView.this.land, str);
						}
						LandViewUtil.inputResultResponse(result, offplayer, cancel, 1107160);
						return cancel;
					}
				});
				player.sendMessage(LanguageManager.getChatLang(1107163, "s", LandViewUtil.getLandLabelStr(LandInfoView.this.land)));
				view.finishAll();
			}
		});
		this.setIconClick(config_view.getViewItemSlot("sell"), new IViewClickHandler() {
			@Override
			public void onClick(Player player, AbFrameView view, ViewClickReport report) {
				if(!LandInfoView.this.isMatchClickSpeed()) return;
				if(report.isRightClick()) {
					if(LandInfoView.this.land.getPrice() < 0) return;
					final FrameViewIntent intent = new FrameViewIntent(LandSoldInfoView.class);
					final FrameViewBundle fvb = new FrameViewBundle();
					fvb.putValue("land", LandInfoView.this.land);
					intent.putExtras(fvb);
					view.showView(intent);
					return;
				}
				IInputRequestManager.getIInputRequestManager().requestInput(player, "s", ConfigurationManager.View_Choose_Countdown, true, new IInputResultHandler() {
					@Override
					public boolean onInputResult(EInputResult result, OfflinePlayer offplayer, @Nullable String str) {
						boolean cancel = true;
						if(EInputResult.INPUT.equals(result)) {
							cancel = sellLand(player, LandInfoView.this.land, str);
						}
						LandViewUtil.inputResultResponse(result, offplayer, cancel, 1107170);
						return cancel;
					}
				});
				player.sendMessage(LanguageManager.getChatLang(1107171, "s", LandViewUtil.getLandLabelStr(LandInfoView.this.land)));
				view.finishAll();
			}
		});
		this.setIconClick(config_view.getViewItemSlot("level"), config_view.getViewItem("level"), new IViewClickHandler() {
			@Override
			public void onClick(Player player, AbFrameView view, ViewClickReport report) {
				if(!LandInfoView.this.isMatchClickSpeed()) return;
				IInputRequestManager.getIInputRequestManager().requestInput(player, "s", ConfigurationManager.View_Choose_Countdown, true, new IInputResultHandler() {
					@Override
					public boolean onInputResult(EInputResult result, OfflinePlayer offplayer, @Nullable String str) {
						boolean cancel = true;
						if(EInputResult.INPUT.equals(result)) {
							cancel = changeLandLevel(player, LandInfoView.this.land, str);
						}
						LandViewUtil.inputResultResponse(result, offplayer, cancel, 1107180);
						return cancel;
					}
				});
				player.sendMessage(LanguageManager.getChatLang(1107181, "s", LandViewUtil.getLandLabelStr(LandInfoView.this.land)));
				view.finishAll();
			}
		});
		this.setIconClick(config_view.getViewItemSlot("copy"), config_view.getViewItem("copy"), new IViewClickHandler() {
			@Override
			public void onClick(Player player, AbFrameView view, ViewClickReport report) {
				if(!LandInfoView.this.isMatchClickSpeed()) return;
				if(!player.getWorld().getName().equals(LandInfoView.this.land.getWorldName())) return;
				LandRangeToolListener.putLandRange(player, LandInfoView.this.land.getRange().clone());
				player.sendMessage(LanguageManager.getChatLang(1107191, LandViewUtil.getLandLabelStr(LandInfoView.this.land)));
				view.finishAll();
			}
		});
		this.setIconClick(config_view.getViewItemSlot("entertip"), config_view.getViewItem("entertip"), new IViewClickHandler() {
			@Override
			public void onClick(Player player, AbFrameView view, ViewClickReport report) {
				if(!LandInfoView.this.isMatchClickSpeed()) return;
				if(report.isRightClick()) {
					if(LandInfoView.this.land.getLeaveMessage() == null) return;
					final ChooseViewIntentBuilder builder = new ChooseViewIntentBuilder(LandChooseView.class);
					builder.setChooseCountdown(ConfigurationManager.View_Choose_Countdown);
					builder.setCustomPromptName(LanguageManager.getLang(1107203));
					builder.setCustomPromptLore(Util.listFromStr(LanguageManager.getLang(1107204, LandViewUtil.getLandLabelStr(LandInfoView.this.land))));
					LandInfoView.this.showViewForResult(builder.build(), CODE_CHOOSE_NOTENTERTIP);
					return;
				}
				IInputRequestManager.getIInputRequestManager().requestInput(player, "s", ConfigurationManager.View_Choose_Countdown, true, new IInputResultHandler() {
					@Override
					public boolean onInputResult(EInputResult result, OfflinePlayer offplayer, @Nullable String str) {
						boolean cancel = true;
						if(EInputResult.INPUT.equals(result)) {
							cancel = changeLandEnterInput(player, LandInfoView.this.land, str);
						}
						LandViewUtil.inputResultResponse(result, offplayer, cancel, 1107200);
						return cancel;
					}
				});
				player.sendMessage(LanguageManager.getLang(1107206));
				player.sendMessage(LanguageManager.getChatLang(1107201, "s", LandViewUtil.getLandLabelStr(LandInfoView.this.land)));
				view.finishAll();
			}
		});
		this.setIconClick(config_view.getViewItemSlot("leavetip"), config_view.getViewItem("leavetip"), new IViewClickHandler() {
			@Override
			public void onClick(Player player, AbFrameView view, ViewClickReport report) {
				if(!LandInfoView.this.isMatchClickSpeed()) return;
				if(report.isRightClick()) {
					if(LandInfoView.this.land.getLeaveMessage() == null) return;
					final ChooseViewIntentBuilder builder = new ChooseViewIntentBuilder(LandChooseView.class);
					builder.setChooseCountdown(ConfigurationManager.View_Choose_Countdown);
					builder.setCustomPromptName(LanguageManager.getLang(1107213));
					builder.setCustomPromptLore(Util.listFromStr(LanguageManager.getLang(1107204, LandViewUtil.getLandLabelStr(LandInfoView.this.land))));
					LandInfoView.this.showViewForResult(builder.build(), CODE_CHOOSE_NOTLEAVETIP);
					return;
				}
				IInputRequestManager.getIInputRequestManager().requestInput(player, "s", ConfigurationManager.View_Choose_Countdown, true, new IInputResultHandler() {
					@Override
					public boolean onInputResult(EInputResult result, OfflinePlayer offplayer, @Nullable String str) {
						boolean cancel = true;
						if(EInputResult.INPUT.equals(result)) {
							cancel = changeLandLeaveInput(player, LandInfoView.this.land, str);
						}
						LandViewUtil.inputResultResponse(result, offplayer, cancel, 1107200);
						return cancel;
					}
				});
				player.sendMessage(LanguageManager.getLang(1107206));
				player.sendMessage(LanguageManager.getChatLang(1107211, "s", LandViewUtil.getLandLabelStr(LandInfoView.this.land)));
				view.finishAll();
			}
		});
		this.setIconClick(config_view.getViewItemSlot("pos"), config_view.getViewItem("pos"), new IViewClickHandler() {
			@Override
			public void onClick(Player player, AbFrameView view, ViewClickReport report) {
				if(!LandInfoView.this.isMatchClickSpeed()) return;
				final ChooseViewIntentBuilder builder = new ChooseViewIntentBuilder(LandChooseView.class);
				builder.setChooseCountdown(ConfigurationManager.View_Choose_Countdown);
				builder.setCustomPromptName(LanguageManager.getLang(1107221));
				final LandPosition pos = new LandPosition(player.getLocation());
				builder.setCustomPromptLore(Util.listFromStr(LanguageManager.getLang(1107222, LandViewUtil.getLandLabelStr(LandInfoView.this.land),
						pos.getX(), pos.getY(), pos.getZ())));
				builder.setForwardContent(pos);
				LandInfoView.this.showViewForResult(builder.build(), CODE_CHOOSE_SETPOS);
			}
		});
		this.setIconClick(config_view.getViewItemSlot("overlap"), config_view.getViewItem("overlap"), new IViewClickHandler() {
			@Override
			public void onClick(Player player, AbFrameView view, ViewClickReport report) {
				if(!LandInfoView.this.isMatchClickSpeed()) return;
				final ChooseViewIntentBuilder builder = new ChooseViewIntentBuilder(LandChooseView.class);
				builder.setChooseCountdown(ConfigurationManager.View_Choose_Countdown);
				builder.setCustomPromptName(LanguageManager.getLang(1107231));
				final boolean overlap = !LandInfoView.this.land.isOverLap();
				builder.setCustomPromptLore(Util.listFromStr(LanguageManager.getLang(1107232, LandViewUtil.getLandLabelStr(LandInfoView.this.land),
						LanguageManager.getLang(overlap ? 1107100 : 1107101))));
				builder.setForwardContent(overlap);
				LandInfoView.this.showViewForResult(builder.build(), CODE_CHOOSE_OVERLAP);
			}
		});
		this.setIconClick(config_view.getViewItemSlot("system"), config_view.getViewItem("system"), new IViewClickHandler() {
			@Override
			public void onClick(Player player, AbFrameView view, ViewClickReport report) {
				if(!LandInfoView.this.isMatchClickSpeed()) return;
				final ChooseViewIntentBuilder builder = new ChooseViewIntentBuilder(LandChooseView.class);
				builder.setChooseCountdown(ConfigurationManager.View_Choose_Countdown);
				builder.setCustomPromptName(LanguageManager.getLang(1107241));
				final boolean system = !LandInfoView.this.land.isSystem();
				builder.setCustomPromptLore(Util.listFromStr(LanguageManager.getLang(1107242, LandViewUtil.getLandLabelStr(LandInfoView.this.land),
						LanguageManager.getLang(system ? 1107100 : 1107101))));
				builder.setForwardContent(system);
				LandInfoView.this.showViewForResult(builder.build(), CODE_CHOOSE_SYSTEM);
			}
		});
		this.setIconClick(config_view.getViewItemSlot("delete"), config_view.getViewItem("delete"), new IViewClickHandler() {
			@Override
			public void onClick(Player player, AbFrameView view, ViewClickReport report) {
				if(!LandInfoView.this.isMatchClickSpeed()) return;
				final ChooseViewIntentBuilder builder = new ChooseViewIntentBuilder(LandChooseView.class);
				builder.setChooseCountdown(ConfigurationManager.View_Choose_Countdown);
				builder.setCustomPromptName(LanguageManager.getLang(1107251));
				builder.setCustomPromptLore(Util.listFromStr(LanguageManager.getLang(1107252, LandViewUtil.getLandLabelStr(LandInfoView.this.land))));
				LandInfoView.this.showViewForResult(builder.build(), CODE_CHOOSE_DELETE);
			}
		});
		if(ELandType.TERRITORY.equals(this.land.getType())) {
			final ItemStack item = config_view.getViewItem("change");
			final ItemMeta meta = item.getItemMeta();
			final int price_service = Math.max(0, (ConfigurationManager.Community_Create_Price - ConfigurationManager.Territory_Create_Price));
			final double price_cost = Math.max(0d, ArithmeticUtil.subtract(LandCreateView.getCreateCostPrice(ELandType.COMMUNITY,
					this.land.getWorldName(), this.getPlayer()), LandCreateView.getCreateCostPrice(ELandType.TERRITORY,
							this.land.getWorldName(), this.getPlayer())));
			//这里显示价格费用，lang-1107010
			meta.setLore(Util.listFromStr(LanguageManager.getLang(1107010, price_service, price_service)));
			item.setItemMeta(meta);
			this.setIconClick(config_view.getViewItemSlot("change"), item, new IViewClickHandler() {
				private final int price_service1 = price_service;
				private final double price_cost1 = price_cost;
				@Override
				public void onClick(Player player, AbFrameView view, ViewClickReport report) {
					if(!LandInfoView.this.isMatchClickSpeed()) return;
					final long size = LandInfoView.this.land.getRangeSize();
					final double price_range = ArithmeticUtil.multiply(size, this.price_cost1, 2);
					final double price_pay = ArithmeticUtil.add(this.price_service1, price_range);
					//这里开始计算价格并显示到选择提示中，lang-1107262
					final ChooseViewIntentBuilder builder = new ChooseViewIntentBuilder(LandChooseView.class);
					builder.setChooseCountdown(ConfigurationManager.View_Choose_Countdown);
					builder.setCustomPromptName(LanguageManager.getLang(1107261));
					builder.setCustomPromptLore(Util.listFromStr(LanguageManager.getLang(1107262, size, this.price_cost1,
							price_range, this.price_service1, price_pay)));
					builder.setForwardContent(price_pay); //传递价格
					LandInfoView.this.showViewForResult(builder.build(), CODE_CHOOSE_CHANGE);
				}
			});
		}
		//自定义输入扩大范围格数
		StringBuilder strb = new StringBuilder(LanguageManager.getLang(1107013));
		strb.append("\n").append(LanguageManager.getLang(1107011, ConfigurationManager.View_LandInfo_Expand_Price));
		this.setIconClick(config_view.getViewItemSlot("expand_input"), ViewsConfiguration.setItemMeta(config_view.getViewItem("expand_input")
				, null, Util.listFromStr(strb.toString())), new IViewClickHandler() {
			@Override
			public void onClick(Player player, AbFrameView view, ViewClickReport report) {
				if(!LandInfoView.this.isMatchClickSpeed()) return;
				IInputRequestManager.getIInputRequestManager().requestInput(player, "s", ConfigurationManager.View_Choose_Countdown,
						true, new IInputResultHandler() {
					@Override
					public boolean onInputResult(EInputResult result, OfflinePlayer offplayer, @Nullable String str) {
						boolean cancel = true;
						if(EInputResult.INPUT.equals(result)) {
							cancel = LandInfoView.this.inputLandRange(str, true);
						}
						if(cancel) LandInfoView.this.finishAll();
						LandViewUtil.inputResultResponse(result, offplayer, cancel, 1107300);
						return cancel;
					}
				});
				player.sendMessage(LanguageManager.getChatLang(1107306, "s", LandViewUtil.getLandLabelStr(LandInfoView.this.land)));
				view.hidden();
			}
		});
		//固定扩大范围格数
		strb = new StringBuilder(LanguageManager.getLang(1107012));
		strb.append("\n").append(LanguageManager.getLang(1107011, ConfigurationManager.View_LandInfo_Expand_Price));
		List<String> expand_lore = Util.listFromStr(strb.toString());
		this.setIconClick(config_view.getViewItemSlot("expand_1"), ViewsConfiguration.setItemMeta(config_view.getViewItem("expand_1"),
				null, expand_lore), new IViewClickHandler() {
			@Override
			public void onClick(Player player, AbFrameView view, ViewClickReport report) {
				if(!LandInfoView.this.isMatchClickSpeed()) return;
				showExpandLandRangeChoose(1);
			}
		});
		this.setIconClick(config_view.getViewItemSlot("expand_5"), ViewsConfiguration.setItemMeta(config_view.getViewItem("expand_5"),
				null, expand_lore), new IViewClickHandler() {
			@Override
			public void onClick(Player player, AbFrameView view, ViewClickReport report) {
				if(!LandInfoView.this.isMatchClickSpeed()) return;
				showExpandLandRangeChoose(5);
			}
		});
		this.setIconClick(config_view.getViewItemSlot("expand_10"), ViewsConfiguration.setItemMeta(config_view.getViewItem("expand_10"),
				null ,expand_lore), new IViewClickHandler() {
			@Override
			public void onClick(Player player, AbFrameView view, ViewClickReport report) {
				if(!LandInfoView.this.isMatchClickSpeed()) return;
				showExpandLandRangeChoose(10);
			}
		});
		//自定义输入扩大范围格数
		strb = new StringBuilder(LanguageManager.getLang(1107022));
		strb.append("\n").append(LanguageManager.getLang(1107020, ConfigurationManager.View_LandInfo_Reduce_Price));
		this.setIconClick(config_view.getViewItemSlot("reduce_input"), ViewsConfiguration.setItemMeta(config_view.getViewItem("reduce_input")
				,null , Util.listFromStr(strb.toString())), new IViewClickHandler() {
			@Override
			public void onClick(Player player, AbFrameView view, ViewClickReport report) {
				if(!LandInfoView.this.isMatchClickSpeed()) return;
				IInputRequestManager.getIInputRequestManager().requestInput(player, "s", ConfigurationManager.View_Choose_Countdown,
						true, new IInputResultHandler() {
					@Override
					public boolean onInputResult(EInputResult result, OfflinePlayer offplayer, @Nullable String str) {
						boolean cancel = true;
						if(EInputResult.INPUT.equals(result)) {
							cancel = LandInfoView.this.inputLandRange(str, false);
						}
						if(cancel) LandInfoView.this.finishAll();
						LandViewUtil.inputResultResponse(result, offplayer, cancel, 1107320);
						return cancel;
					}
				});
				player.sendMessage(LanguageManager.getChatLang(1107327, "s", LandViewUtil.getLandLabelStr(LandInfoView.this.land)));
				view.hidden();
			}
		});
		//固定缩小范围格数
		strb = new StringBuilder(LanguageManager.getLang(1107021));
		strb.append("\n").append(LanguageManager.getLang(1107020, ConfigurationManager.View_LandInfo_Reduce_Price));
		List<String> reduce_lore = Util.listFromStr(strb.toString());
		this.setIconClick(config_view.getViewItemSlot("reduce_1"), ViewsConfiguration.setItemMeta(config_view.getViewItem("reduce_1"),
				null, reduce_lore), new IViewClickHandler() {
			@Override
			public void onClick(Player player, AbFrameView view, ViewClickReport report) {
				if(!LandInfoView.this.isMatchClickSpeed()) return;
				showReduceLandRangeChoose(1);
			}
		});
		this.setIconClick(config_view.getViewItemSlot("reduce_5"), ViewsConfiguration.setItemMeta(config_view.getViewItem("reduce_5"),
				null, reduce_lore), new IViewClickHandler() {
			@Override
			public void onClick(Player player, AbFrameView view, ViewClickReport report) {
				if(!LandInfoView.this.isMatchClickSpeed()) return;
				showReduceLandRangeChoose(5);
			}
		});
		this.setIconClick(config_view.getViewItemSlot("reduce_10"), ViewsConfiguration.setItemMeta(config_view.getViewItem("reduce_10"),
				null, reduce_lore), new IViewClickHandler() {
			@Override
			public void onClick(Player player, AbFrameView view, ViewClickReport report) {
				if(!LandInfoView.this.isMatchClickSpeed()) return;
				showReduceLandRangeChoose(10);
			}
		});
	}
	
	@Override
	protected void onShowBefore() {
		super.onShowBefore();
		final ViewConfig config_view = ViewsConfiguration.getViewConfig(VIEW_NAME);
		ItemStack item = config_view.getViewItem("about");
		ItemMeta meta = item.getItemMeta();
		meta.setDisplayName(Util.setStr(meta.getDisplayName(), this.land.getID(), this.land.getName()));
		meta.setLore(LandViewUtil.getLandInfoItemStack(this.land));
		item.setItemMeta(meta);
		this.setIcon(config_view.getViewItemSlot("about"), item);
		
		item = config_view.getViewItem("sell");
		meta = item.getItemMeta();
		int lang = (this.land.getPrice() < 0 ? 1107030 : 1107031);
		meta.setLore(Util.listFromStr((LanguageManager.getLang(lang) + "\n" + LanguageManager.getLang(1107032))));
		item.setItemMeta(meta);
		this.setIcon(config_view.getViewItemSlot("sell"), item);
	}
	
	@Override
	protected void onViewResult(int requestcode, int resultcode, @Nullable FrameViewBundle bundle) {
		super.onViewResult(requestcode, resultcode, bundle);
		switch(EChooseResult.muchResult(resultcode)) {
		case CONFIRM:
			if(requestcode == CODE_CHOOSE_NOTENTERTIP) {//进入领地消息设置无
				setLandNotEnterMessage(this.getPlayer(), this.land);
				break;
			}
			if(requestcode == CODE_CHOOSE_NOTLEAVETIP) {//离开领地消息设置无
				setLandNotLeaveMessage(this.getPlayer(), this.land);
				break;
			}
			if(requestcode == CODE_CHOOSE_SETPOS) {//传送点
				setLandPos(this.getPlayer(), this.land, bundle.getValue(EChooseResultIntentKey.FORWARD.toString(), null));
				break;
			}
			if(requestcode == CODE_CHOOSE_OVERLAP) {//领地重叠
				changeLandOverLap(this.getPlayer(), this.land, bundle.getValue(EChooseResultIntentKey.FORWARD.toString(), false));
				break;
			}
			if(requestcode == CODE_CHOOSE_SYSTEM) {//系统状态
				changeLandSystem(this.getPlayer(), this.land, bundle.getValue(EChooseResultIntentKey.FORWARD.toString(), false));
				break;
			}
			if(requestcode == CODE_CHOOSE_DELETE) {//删除领地
				deleteLand(this.getPlayer(), this.land);
				break;
			}
			if(requestcode == CODE_CHOOSE_CHANGE) {//变更为小区
				changeLandType(this.getPlayer(), this.land, bundle.getValue(EChooseResultIntentKey.FORWARD.toString(), 0d));
				break;
			}
			if(requestcode == CODE_CHOOSE_EXPAND) {//扩展领地
				final HashMap<String,Object> values = bundle.getValue(EChooseResultIntentKey.FORWARD.toString(), null);
				expandLandRange((LandRange)values.get("range_old"), (LandRange)values.get("range_new"), (BlockFace)values.get("face"), 
						(int)values.get("grid"), (double)values.get("pay"));
				break;
			}
			if(requestcode == CODE_CHOOSE_REDUCE) {//缩小领地
				final HashMap<String,Object> values = bundle.getValue(EChooseResultIntentKey.FORWARD.toString(), null);
				reduceLandRange((LandRange)values.get("range_old"), (LandRange)values.get("range_new"), (BlockFace)values.get("face"), 
						(int)values.get("grid"), (int)values.get("pay"));
				break;
			}
			this.getPlayer().sendMessage(LanguageManager.getChatLang(1001001) + requestcode);
			break;
		case VETO:
			return;
		default:
		}
		this.finishAll();
	}
	private boolean inputLandRange(@Nullable String str,boolean expand) {
		if(str == null || !Pattern.matches("^\\d{1,6}$", str)) {
			LandViewUtil.sendInputNotInconformity(this.getPlayer(), (expand ? 1107300 : 1107320));
			return false;
		}
		final int grid = Integer.valueOf(str);
		if(grid == 0) {
			LandViewUtil.sendInputMustPositiveNumber(this.getPlayer());
			return false;
		}
		if(expand) {
			this.showExpandLandRangeChoose(grid);
		}else {
			this.showReduceLandRangeChoose(grid);
		}
		return true;
	}
	private void showReduceLandRangeChoose(int grid) {
		final BlockFace face = Util.getEntityLockFace(this.getPlayer());
		final LandRange range_reduce = this.land.getRange().clone();
		range_reduce.reduce(face, grid);
		if(range_reduce.equals(this.land.getRange())) {
			this.getPlayer().sendMessage(LanguageManager.getChatLang(1107323, LandViewUtil.getLandLabelStr(this.land),
					LandViewUtil.getFaceStr(face), grid));
			return;
		}
		final ChooseViewIntentBuilder builder = new ChooseViewIntentBuilder(LandChooseView.class);
		builder.setChooseCountdown(ConfigurationManager.View_Choose_Countdown);
		builder.setCustomPromptName(LanguageManager.getLang(1107321));
		final long size = (land.getRangeSize() - range_reduce.getSize());
		final int price_pay = ConfigurationManager.View_LandInfo_Reduce_Price;
		builder.setCustomPromptLore(Util.listFromStr(LanguageManager.getLang(1107322, size, price_pay)));
		final HashMap<String,Object> map_values = new HashMap<>();
		map_values.put("pay", price_pay);
		map_values.put("range_new", range_reduce);
		map_values.put("range_old", this.land.getRange().clone());
		map_values.put("face", face);
		map_values.put("grid", grid);
		builder.setForwardContent(map_values);
		this.showViewForResult(builder.build(), CODE_CHOOSE_REDUCE);
	}
	private void showExpandLandRangeChoose(int grid) {
		final LandRange range_expand = this.land.getRange().clone();
		final BlockFace face = Util.getEntityLockFace(this.getPlayer());
		range_expand.expand(face, grid);
		final ChooseViewIntentBuilder builder = new ChooseViewIntentBuilder(LandChooseView.class);
		builder.setChooseCountdown(ConfigurationManager.View_Choose_Countdown);
		builder.setCustomPromptName(LanguageManager.getLang(1107301));
		final long size = (range_expand.getSize() - this.land.getRangeSize());
		final double price_cost = LandCreateView.getCreateCostPrice(this.land.getType(), land.getWorldName(), this.getPlayer());
		final int price_service = ConfigurationManager.View_LandInfo_Expand_Price;
		final double price_range = ArithmeticUtil.multiply(size, price_cost, 2);
		final double price_pay = ArithmeticUtil.add(price_service, price_range);
		builder.setCustomPromptLore(Util.listFromStr(LanguageManager.getLang(1107302, size, price_cost, price_range, 
				price_service, price_pay)));
		final HashMap<String,Object> map_values = new HashMap<>();
		map_values.put("pay", price_pay);
		map_values.put("range_new", range_expand);
		map_values.put("range_old", this.land.getRange().clone());
		map_values.put("face", face);
		map_values.put("grid", grid);
		builder.setForwardContent(map_values);
		this.showViewForResult(builder.build(), CODE_CHOOSE_EXPAND);
	}
	private void reduceLandRange(LandRange range_old, LandRange range_new, BlockFace face, int grid, int price_pay) {
		if(this.land.isDeleted()) return;
		final Player player = this.getPlayer();
		final World world = Bukkit.getWorld(this.land.getWorldName());
		if(world == null) {
			this.getPlayer().sendMessage(LanguageManager.getChatLang(1106123, WorldsConfiguration.getWorldName(this.land.getWorldName())));
			return;
		}
		if(!LandViewUtil.isRangeAccordWithLand(range_new, this.land.getType(), player)) return;
		if(!LandViewUtil.hasSendUsePermission(player, this.land.getWorldName(), ConfigurationManager.View_LandInfo_Reduce_Per, 1107320)) return;
		if(!LandViewUtil.hasSendLandPermission(player, this.land, ELandPermissionLevel.OWNER, 1107320)) return;
		if(!this.land.getRange().equals(range_old)) {
			player.sendMessage(LanguageManager.getChatLang(1107303, LandViewUtil.getLandLabelStr(this.land)));
			return;
		}
		if(!LandViewUtil.checkRangeReduceCollision(player, this.land, range_new)) return;
		if(price_pay > 0 && !player.isOp() && !Econ.getEcon().take(player, price_pay)) {
			player.sendMessage(LanguageManager.getChatLang(1107324, LandViewUtil.getLandLabelStr(this.land),
					LandViewUtil.getFaceStr(face), grid, price_pay));
			return;
		}
		final LandRangeUpdateEvent event = new LandRangeUpdateEvent(player, this.land, range_new);
		Bukkit.getPluginManager().callEvent(event);
		if(event.isCancelled()) {
			if(price_pay > 0 && !player.isOp() && !Econ.getEcon().give(player, price_pay)) {
				LandTerritoryMain.getPlugin().getLogger().warning(LanguageManager.getLang(1001002, player.getName(),
						player.getUniqueId().toString(),price_pay,"give"));
				player.sendMessage(LanguageManager.getChatLang(1001004, price_pay));
				return;
			}
			player.sendMessage(LanguageManager.getChatLang(1107326, LandViewUtil.getLandLabelStr(this.land),
					LandViewUtil.getFaceStr(face), grid));
			return;
		}
		LandManager.getLandManager().removeLandInHash(range_old, this.land);
		this.land.setRange(range_new);
		LandManager.getLandManager().addLandInHash(range_new, this.land);
		player.sendMessage(LanguageManager.getChatLang(1107325, price_pay, LandViewUtil.getLandLabelStr(this.land),
				LandViewUtil.getFaceStr(face), grid));
		LandViewUtil.checkSendLandPosInRange(player, this.land);
	}
	private void expandLandRange(LandRange range_old, LandRange range_new, BlockFace face, int grid, double price_pay) {
		if(this.land.isDeleted()) return;
		final Player player = this.getPlayer();
		if(!LandViewUtil.isHighlyAccordWithWorld(range_new, Bukkit.getWorld(range_new.getWorldName()), this.getPlayer())) return;
		if(!LandViewUtil.isRangeAccordWithLand(range_new, this.land.getType(), player)) return;
		if(!LandViewUtil.hasSendUsePermission(player, this.land.getWorldName(), ConfigurationManager.View_LandInfo_Expand_Per, 1107300)) return;
		if(!LandViewUtil.hasSendLandPermission(player, this.land, ELandPermissionLevel.FLAG_LANDADMIN, 1107300)) return;
		if(!this.land.getRange().equals(range_old)) {
			player.sendMessage(LanguageManager.getChatLang(1107303, LandViewUtil.getLandLabelStr(this.land)));
			return;
		}
		if(!LandViewUtil.checkRangeExpandCollision(player, this.land, range_new)) return;
		if(price_pay > 0d && !player.isOp() && !Econ.getEcon().take(player, price_pay)) {
			player.sendMessage(LanguageManager.getChatLang(1107304, LandViewUtil.getLandLabelStr(this.land),
					LandViewUtil.getFaceStr(face), grid, price_pay));
			return;
		}
		final LandRangeUpdateEvent event = new LandRangeUpdateEvent(player, this.land, range_new);
		Bukkit.getPluginManager().callEvent(event);
		if(event.isCancelled()) {
			if(price_pay > 0d && !player.isOp() && !Econ.getEcon().give(player, price_pay)) {
				LandTerritoryMain.getPlugin().getLogger().warning(LanguageManager.getLang(1001002, player.getName(),
						player.getUniqueId().toString(),price_pay,"give"));
				player.sendMessage(LanguageManager.getChatLang(1001004, price_pay));
				return;
			}
			player.sendMessage(LanguageManager.getChatLang(1107307, LandViewUtil.getLandLabelStr(this.land),
					LandViewUtil.getFaceStr(face), grid));
			return;
		}
		LandManager.getLandManager().removeLandInHash(range_old, this.land);
		this.land.setRange(range_new);
		LandManager.getLandManager().addLandInHash(range_new, this.land);
		player.sendMessage(LanguageManager.getChatLang(1107305, price_pay, LandViewUtil.getLandLabelStr(this.land),
				LandViewUtil.getFaceStr(face), grid));
	}
	private static void changeLandType(final Player player,final Land land,final double price_pay) {
		if(land.isDeleted()) return;
		if(!LandViewUtil.hasSendUsePermission(player, land.getWorldName(), ConfigurationManager.View_LandInfo_Expand_Per, 1107260)) return;
		if(!LandViewUtil.hasSendLandPermission(player, land, ELandPermissionLevel.FLAG_LANDADMIN, 1107260)) return;
		if(ELandType.TERRITORY.equals(land.getType())) {
			if(!LandViewUtil.isRangeAccordWithLand(land.getRange(), ELandType.COMMUNITY, player)) return;
			if(!player.isOp() && !Econ.getEcon().take(player, price_pay)) {
				player.sendMessage(LanguageManager.getChatLang(1107263, price_pay));
				return;
			}
			LandManager.getLandManager().changeLandTypeCommunity(land);
			land.setLevel(ConfigurationManager.View_LandInfo_Change_Level);
			Bukkit.getPluginManager().callEvent(new LandUpdateDataEvent(player, land));
		}
		player.sendMessage(LanguageManager.getChatLang(1004000, price_pay, LanguageManager.getLang(ELandType.TERRITORY.getLang()),
				land.getID(), land.getName()));
	}
	private static void deleteLand(final Player player,final Land land) {
		if(land.isDeleted()) return;
		if(!LandViewUtil.hasSendUsePermission(player, land.getWorldName(), ConfigurationManager.View_LandInfo_Delete, 1107250)) return;
		if(!LandViewUtil.hasSendLandPermission(player, land, ELandPermissionLevel.OWNER, 1107250)) return;
		if(ELandType.COMMUNITY.equals(land.getType())) {
			final LandRange range = land.getRange();
			for(final Land land_ground : LandManager.getLandManager().getServerLands(ELandType.GROUND)) {
				final LandRange range_ground = land_ground.getRange();
				if(range_ground.cover(range) && range_ground.isInRange(range)) {
					player.sendMessage(LanguageManager.getChatLang(1107254, LandViewUtil.getLandLabelStr(land),
							LandViewUtil.getLandLabelStr(land_ground)));
					return;
				}
			}
		}
		try {
			DataBaseManager.getDataBaseCore().deleteLand(land.getID());
		}catch(Exception ex) {
			ex.printStackTrace();
			return;
		}
		land.setDeleted();
		LandManager.getLandManager().removeLandInHash(land.getRange(), land);
		LandManager.getLandManager().removeLandInMemory(land);
		player.sendMessage(LanguageManager.getChatLang(1107253, LandViewUtil.getLandLabelStr(land)));
	}
	private static void changeLandSystem(final Player player,final Land land,final boolean system) {
		if(land.isDeleted()) return;
		if(!LandViewUtil.hasSendUsePermission(player, land.getWorldName(), ConfigurationManager.View_LandInfo_System, 1107240)) return;
		if(!LandViewUtil.hasSendLandPermission(player, land, ELandPermissionLevel.FLAG_LANDADMIN, 1107240)) return;
		if(land.isSystem() != system) {
			land.setSystem(system);
			Bukkit.getPluginManager().callEvent(new LandUpdateDataEvent(player, land));
		}
		player.sendMessage(LanguageManager.getChatLang(1107243, LandViewUtil.getLandLabelStr(land), LanguageManager.getLang(system ? 1107100 : 1107101)));
	}
	private static void changeLandOverLap(final Player player,final Land land,final boolean overlap) {
		if(land.isDeleted()) return;
		if(!LandViewUtil.hasSendUsePermission(player, land.getWorldName(), ConfigurationManager.View_LandInfo_Overlap, 1107230)) return;
		if(!LandViewUtil.hasSendLandPermission(player, land, ELandPermissionLevel.FLAG_LANDADMIN, 1107230)) return;
		if(land.isOverLap() != overlap) {
			land.setOverLap(overlap);
			Bukkit.getPluginManager().callEvent(new LandUpdateDataEvent(player, land));
		}
		player.sendMessage(LanguageManager.getChatLang(1107233, LandViewUtil.getLandLabelStr(land), LanguageManager.getLang(overlap ? 1107100 : 1107101)));
	}
	private static void setLandPos(final Player player,final Land land,final LandPosition pos) {
		if(land.isDeleted()) return;
		if(!LandViewUtil.hasSendUsePermission(player, land.getWorldName(), ConfigurationManager.View_LandInfo_Pos, 1107220)) return;
		if(!LandViewUtil.hasSendLandPermission(player, land, ELandPermissionLevel.FLAG_LANDADMIN, 1107220)) return;
		if(!land.getRange().isInRange(pos)) {
			player.sendMessage(LanguageManager.getChatLang(1107223));
			return;
		}
		land.setPos(pos);
		Bukkit.getPluginManager().callEvent(new LandUpdateDataEvent(player, land));
		player.sendMessage(LanguageManager.getChatLang(1107224, LandViewUtil.getLandLabelStr(land), pos.getX(), pos.getY(), pos.getZ()));
	}
	private static void setLandNotLeaveMessage(final Player player,final Land land) {
		if(land.isDeleted()) return;
		if(!LandViewUtil.hasSendUsePermission(player, land.getWorldName(), ConfigurationManager.View_LandInfo_Tip_Per, 1107210)) return;
		if(!LandViewUtil.hasSendLandPermission(player, land, ELandPermissionLevel.FLAG_LANDADMIN, 1107210)) return;
		if(land.getLeaveMessage() != null) {
			land.setLeaveMessage(null);
			Bukkit.getPluginManager().callEvent(new LandUpdateDataEvent(player, land));
		}
		player.sendMessage(LanguageManager.getChatLang(1107215, LandViewUtil.getLandLabelStr(land)));
	}
	private static void setLandNotEnterMessage(final Player player,final Land land) {
		if(land.isDeleted()) return;
		if(!LandViewUtil.hasSendUsePermission(player, land.getWorldName(), ConfigurationManager.View_LandInfo_Tip_Per, 1107200)) return;
		if(!LandViewUtil.hasSendLandPermission(player, land, ELandPermissionLevel.FLAG_LANDADMIN, 1107200)) return;
		if(land.getEnterMessage() != null) {
			land.setEnterMessage(null);
			Bukkit.getPluginManager().callEvent(new LandUpdateDataEvent(player, land));
		}
		player.sendMessage(LanguageManager.getChatLang(1107205, LandViewUtil.getLandLabelStr(land)));
	}
	private static boolean changeLandLeaveInput(final Player player,final Land land,@Nullable final String str) {
		if(land.isDeleted()) return true;
		if(str == null || str.isEmpty()) {
			LandViewUtil.sendInputNotInconformity(player, 1107210);
			return false;
		}
		if(str.length() > ConfigurationManager.View_LandInfo_Tip_Length) {
			LandViewUtil.sendInputStrLength(player, 1, ConfigurationManager.View_LandInfo_Tip_Length);
			return false;
		}
		if(!LandViewUtil.hasSendUsePermission(player, land.getWorldName(), ConfigurationManager.View_LandInfo_Tip_Per, 1107210)) return true;
		if(!LandViewUtil.hasSendLandPermission(player, land, ELandPermissionLevel.FLAG_LANDADMIN, 1107210)) return true;
		if(land.getLeaveMessage() != null && !land.getLeaveMessage().equals(str)) {
			land.setLeaveMessage(str);
			Bukkit.getPluginManager().callEvent(new LandUpdateDataEvent(player, land));
		}
		player.sendMessage(LanguageManager.getChatLang(1107212, LandViewUtil.getLandLabelStr(land), Util.conver(str)));
		return true;
	}
	private static boolean changeLandEnterInput(final Player player,final Land land,@Nullable final String str) {
		if(land.isDeleted()) return true;
		if(str == null || str.isEmpty()) {
			LandViewUtil.sendInputNotInconformity(player, 1107200);
			return false;
		}
		if(str.length() > ConfigurationManager.View_LandInfo_Tip_Length) {
			LandViewUtil.sendInputStrLength(player, 1, ConfigurationManager.View_LandInfo_Tip_Length);
			return false;
		}
		if(!LandViewUtil.hasSendUsePermission(player, land.getWorldName(), ConfigurationManager.View_LandInfo_Tip_Per, 1107200)) return true;
		if(!LandViewUtil.hasSendLandPermission(player, land, ELandPermissionLevel.FLAG_LANDADMIN, 1107200)) return true;
		if(land.getEnterMessage() != null && !land.getEnterMessage().equals(str)) {
			land.setEnterMessage(str);
			Bukkit.getPluginManager().callEvent(new LandUpdateDataEvent(player, land));
		}
		player.sendMessage(LanguageManager.getChatLang(1107202, LandViewUtil.getLandLabelStr(land), Util.conver(str)));
		return true;
	}
	private static boolean changeLandLevel(final Player player,final Land land,@Nullable final String str) {
		if(land.isDeleted()) return true;
		if(str == null || str.isEmpty()) {
			LandViewUtil.sendInputNotInconformity(player, 1107180);
			return false;
		}
		if(!Pattern.matches("^\\d{1,3}$", str)) {
			LandViewUtil.sendInputMustNotNegativeNumber(player);
			return false;
		}
		if(!LandViewUtil.hasSendUsePermission(player, land.getWorldName(), ConfigurationManager.View_LandInfo_Level, 1107180)) return true;
		if(!LandViewUtil.hasSendLandPermission(player, land, ELandPermissionLevel.OWNER, 1107180)) return true;
		final int level = Integer.valueOf(str);
		if(land.getLevel() != level) {
			land.setLevel(level);
			Bukkit.getPluginManager().callEvent(new LandUpdateDataEvent(player, land));
		}
		player.sendMessage(LanguageManager.getChatLang(1107182, LandViewUtil.getLandLabelStr(land), str));
		return true;
	}
	private static boolean sellLand(final Player player,final Land land,@Nullable final String str) {
		if(land.isDeleted()) return true;
		String per = null;
		switch(land.getType()){
		case TERRITORY:
			per = ConfigurationManager.Territory_Sell_SellPer;
			break;
		case COMMUNITY:
			per = ConfigurationManager.Community_Sell_SellPer;
			break;
		case GROUND:
			per = ConfigurationManager.Ground_Sell_SellPer;
			break;
		default:
		}
		if(!LandViewUtil.hasSendUsePermission(player, land.getWorldName(), per, 1107170)) return true;
		if(!LandViewUtil.hasSendLandPermission(player, land, ELandPermissionLevel.OWNER, 1107170)) return true;
		if(str == null || str.isEmpty()) {
			LandViewUtil.sendInputNotInconformity(player, 1107170);
			return false;
		}
		if(!Pattern.matches("^\\d{1,9}$", str)) {
			LandViewUtil.sendInputMustNotNegativeNumber(player);
			return false;
		}
		final int price = Integer.valueOf(str);
		if(land.getPrice() != price) {
			if(land.getPrice() < 0) LandManager.getLandManager().getSoldLands().add(land);
			land.setPrice(price);
		}
		player.sendMessage(LanguageManager.getChatLang(1107172, LandViewUtil.getLandLabelStr(land), str));
		return true;
	}
	private static boolean changeLandName(final Player player,final Land land,@Nullable final String str) {
		if(land.isDeleted()) return true;
		if(str == null || str.isEmpty() || Pattern.matches("\\s+", str)) {
			LandViewUtil.sendInputNotInconformity(player, 1107160);
			return false;
		}
		if(str.length() < 3 || str.length() > Math.min(30, ConfigurationManager.View_LandInfo_Name_Length)) {
			LandViewUtil.sendInputStrLength(player, 3, Math.min(30, ConfigurationManager.View_LandInfo_Name_Length));
			return false;
		}
		if(Pattern.matches("^\\d+$", str)) {
			LandViewUtil.sendInputNotOnlyNumber(player);
			return false;
		}
		if(LandManager.getLandManager().getLand(str) != null) {
			player.sendMessage(LanguageManager.getChatLang(1107162, str));
			return false;
		}
		if(!LandViewUtil.hasSendUsePermission(player, land.getWorldName(), ConfigurationManager.View_LandInfo_Name_Per, 1107160)) return true;
		if(!LandViewUtil.hasSendLandPermission(player, land, ELandPermissionLevel.FLAG_LANDADMIN, 1107160)) return true;
		LandManager.getLandManager().changeLandName(land, str);
		Bukkit.getPluginManager().callEvent(new LandUpdateDataEvent(player, land));
		player.sendMessage(LanguageManager.getChatLang(1107164, LandViewUtil.getLandLabelStr(land), str));
		return true;
	}
	private static boolean changeLandOwner(final Player player,final Land land,@Nullable final String str) {
		if(land.isDeleted()) return true;
		if(str == null || str.isEmpty() || str.length() > 35) {
			LandViewUtil.sendInputNotInconformity(player, 1107150);
			return false;
		}
		if(!LandViewUtil.hasSendUsePermission(player, land.getWorldName(), ConfigurationManager.View_LandInfo_Owner, 1107150)) return true;
		if(!LandViewUtil.hasSendLandPermission(player, land, ELandPermissionLevel.OWNER, 1107150)) return true;
		final Player player_tager = Bukkit.getPlayer(str);
		UUID player_uuid_tager = null;
		if(player_tager == null) {
			for(final OfflinePlayer offplayer : Bukkit.getOfflinePlayers()) {
				if(offplayer.getName().equals(str) && offplayer.hasPlayedBefore()) {
					player_uuid_tager = offplayer.getUniqueId();
					break;
				}
			}
		}else {
			player_uuid_tager = player_tager.getUniqueId();
		}
		if(player_uuid_tager == null) {
			LandViewUtil.sendInputNotFoundPlayer(player, str);
			return false;
		}
		if(land.getOwner().equals(player_uuid_tager)) {
			player.sendMessage(LanguageManager.getChatLang(1107151));
			return false;
		}
		if(!LandUtil.canHasNewLand(player_uuid_tager, land.getType())) {
			player.sendMessage(LanguageManager.getChatLang(1107152, str));
			return true;
		}
		if(land.getPrice() >= 0) {
			land.setPrice(-1);
			LandManager.getLandManager().getSoldLands().remove(LandManager.getLandManager().getSoldLands().indexOf(land));
		}
		LandManager.getLandManager().changeLandOwner(land, player_uuid_tager);
		Bukkit.getPluginManager().callEvent(new LandUpdateDataEvent(player, land));
		final String landstr = LandViewUtil.getLandLabelStr(land);
		player.sendMessage(LanguageManager.getChatLang(1107153, landstr, str));
		if(player_tager != null) player_tager.sendMessage(LanguageManager.getChatLang(1107154, landstr));
		return true;
	}
}